<?php

namespace Apps\AppApi\Method\Question;

use Apps\AppApi\Method\BaseMethod;
use PhalconPlus\Api\Common\ResultStatus;
use Apps\Common\Models\QuestionReport;


/**
 * 举报问题/问题的回复
 * @package Apps\AppApi\Method\Question
 */
class Report extends BaseMethod
{
    public function run()
    {
        if(false == $this->verifyUserAuth()){
            return false;
        }
        $content = $this->getDataItem('content', '');
        $city_code = $this->getDataItem('city_code', '0');
        $question_id = intval($this->getDataItem('question_id', 0)); // 问题id
        $question_reply_id = intval($this->getDataItem('question_reply_id', 0)); // 问题回复的id
        $user_id = $user_id = $this->getUserAuth()->userId;
        $type = $this->getDataItem('type', 1); // 举报类型（1=》问题，2=》问题的回复）
        // 举报类型预留在这里，功能未实现

        if (empty($content) || $question_id == 0 || ($type != 1 && $question_reply_id == 0)) {
            return $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, '缺少必传参数！');
        }
        $length = $this->utf8_strlen($content);
        if ($length < 10 || $length > 30) {
            return $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, '举报内容长度需在10~30字符之间');
        }

        (new QuestionReport())->save([
            'question_id' => $question_id,
            'user_id' => $user_id,
            'report_content' => $content,
            'city_id' => $this->getCityId($city_code),
            'city_code' => $city_code,
            'report_addtime' => date('Y-m-d H:i:s')
        ]);

        $this->setResult(['success' => 1, 'message' => '举报成功！']);
    }

}